package com.yld.scott.ch12;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.junit.Test;

public class FileTest {
	
	
	
	@Test
	public void read() throws Exception {
		
		//1 派侦查兵  相对目录  poi
		File file = new File("src/main/resources/read.conf");
		
		System.out.println(file.getName());
		
		
		//往read.txt上插入一根管子  让数据流进来
		InputStream  fis = new FileInputStream(file);
		
		//文件中有几个单词 我们就循环多少次  
		int len;
		
		while((len= fis.read()) !=-1){
			System.out.println((char)len);
		}
		
		fis.close();
	}
	@Test
	public void readMany() throws Exception {
		//1 派侦查兵  相对目录
		File file = new File("src/main/resources/read.txt");
		
		System.out.println(file.length());
		
		
		//往read.txt上插入一根管子  让数据流进来
		FileInputStream  fis = new FileInputStream(file);
		
		//文件中有几个单词 我们就循环多少次  
		int ascii = fis.read();
		
		while(ascii !=-1){
			System.out.print((char)ascii);
			ascii = fis.read();
		}
		
		fis.close();
	}
	
	
	@Test
	public void readOne() throws Exception {
		//1 派侦查兵  相对目录
		File file = new File("src/main/resources/read.txt");
		
		System.out.println(file.length());
		
		
		//往read.txt上插入一根管子  让数据流进来
		FileInputStream  fis = new FileInputStream(file);
		
		int ascii = fis.read();
		System.out.print((char)ascii);
		
		fis.close();
	}

}
